using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Cysharp.Threading.Tasks;



//AsyncOperation��Awaiter
//Unity�����Դ���һЩ�첽������Ҳ������await�ˡ�
//����:��Դ�첽����
public class Seven : MonoBehaviour
{
    public Button btn1;
    public Text text1;

    public Button btn2;
    public Text text2;
    private void Awake()
    {
        text1=GameObject.Find("Text1").GetComponent<Text>();
        text2 = GameObject.Find("Text2").GetComponent<Text>();
    }
    void Start()
    {
        btn1.onClick.AddListener(() => StartCoroutine(ResNormal()));
        btn2.onClick.AddListener(() => ResUniTask());
    }

    public IEnumerator ResNormal()
    {
      ResourceRequest res=  Resources.LoadAsync<TextAsset>("1");

        while(!res.isDone)
        {
            yield return null;
        }

        if(res.asset!=null)
        {
            text1.text = ((TextAsset)res.asset).text;
        }
    }
   

    public async void ResUniTask()
    {
        ResourceRequest res = Resources.LoadAsync<TextAsset>("1");

        var source=   await res;

       text2.text = ((TextAsset)source).text;
    }
}
